/*
 * Regola grammaticale:
 * <termp> → <fact> [POWER <fact>]*
 *
 * Simboli terminali:
 * POWER → "^"
 */
package composite.number_expression;

import composite.Component;
import composite.NumberExpression;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import visitor.Visitor;

/**
 *
 * @author Antonio
 */
public class Termp extends NumberExpression {

    private List<Component> fact;

    public Termp(Component fact) {

        if (fact == null) {

            throw new NullPointerException();
        }

        this.fact = new LinkedList();
        this.fact.add(fact);
    }

    @Override
    public void add(Component fc) {

        if (fc == null) {

            throw new NullPointerException();
        }

        fact.add(fc);
    }

    public List<Component> getStato() {

        return fact;
    }// getStato

    @Override
    public void interpreta(String contesto) {

        for (Component fa : fact) {

            fa.interpreta(contesto);
        }
    }

    @Override
    public void accept(Visitor v) {

        v.visit(this);
    }

    @Override
    public String toString() {

        StringBuilder sb = new StringBuilder();
        Iterator<Component> it = fact.iterator();

        sb.append(it.next());

        while (it.hasNext()) {

            sb.append(" ^ ").append(it.next());
        }
        return sb.toString();
    }
}
